home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Images, Bitmaps, and Metafiles / Loading and Displaying Bitmaps / GDITEST41.dpr
Encoding:
Text File  |  2003-10-15  |  2.4 KB  |  99 lines

  1. program GDITEST41;
  2.  
  3. uses
  4.   Classes,
  5.   Windows,
  6.   Messages,
  7.   SysUtils,
  8.   GDIPAPI,
  9.   GDIPOBJ;
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   Image: TGPImage;
  15.   bitmap: TGPBitmap;
  16.   Icon: HICON;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   // from file
  20.   Image:= TGPImage.Create('..\..\Media\FRUIT.JPG');
  21.   graphics.DrawImage(Image,60,10);
  22.  
  23.   // from HIcon
  24.   Icon := LoadIcon(0, IDI_QUESTION);
  25.   bitmap:= TGPBitmap.Create(Icon);
  26.   graphics.DrawImage(bitmap, 10, 10);
  27.  
  28.   bitmap.Free;
  29.   Image.Free;
  30.   graphics.Free;
  31. end;
  32.  
  33.  
  34. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  35. var
  36.   Handle: HDC;
  37.   ps: PAINTSTRUCT;
  38. begin
  39.   case message of
  40.     WM_PAINT:
  41.       begin
  42.         Handle := BeginPaint(Wnd, ps);
  43.         OnPaint(Handle);
  44.         EndPaint(Wnd, ps);
  45.         result := 0;
  46.       end;
  47.  
  48.     WM_DESTROY:
  49.       begin
  50.         PostQuitMessage(0);
  51.         result := 0;
  52.       end;
  53.  
  54.    else
  55.       result := DefWindowProc(Wnd, message, wParam, lParam);
  56.    end;
  57. end;
  58.  
  59. var
  60.   hWnd     : THandle;
  61.   Msg      : TMsg;
  62.   wndClass : TWndClass;
  63. begin
  64.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  65.    wndClass.lpfnWndProc    := @WndProc;
  66.    wndClass.cbClsExtra     := 0;
  67.    wndClass.cbWndExtra     := 0;
  68.    wndClass.hInstance      := hInstance;
  69.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  70.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  71.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  72.    wndClass.lpszMenuName   := nil;
  73.    wndClass.lpszClassName  := 'GettingStarted';
  74.  
  75.    RegisterClass(wndClass);
  76.  
  77.    hWnd := CreateWindow(
  78.       'GettingStarted',       // window class name
  79.       'Loading and Displaying Bitmaps',       // window caption
  80.       WS_OVERLAPPEDWINDOW,    // window style
  81.       Integer(CW_USEDEFAULT), // initial x position
  82.       Integer(CW_USEDEFAULT), // initial y position
  83.       Integer(CW_USEDEFAULT), // initial x size
  84.       Integer(CW_USEDEFAULT), // initial y size
  85.       0,                      // parent window handle
  86.       0,                      // window menu handle
  87.       hInstance,              // program instance handle
  88.       nil);                   // creation parameters
  89.  
  90.    ShowWindow(hWnd, SW_SHOW);
  91.    UpdateWindow(hWnd);
  92.  
  93.    while(GetMessage(msg, 0, 0, 0)) do
  94.    begin
  95.       TranslateMessage(msg);
  96.       DispatchMessage(msg);
  97.    end;
  98. end.
  99.